/*           Copyright(c) 2005-2008 Dave Sexton            *
 *                   HtmlEditor Control                    *
 * http://www.codeplex.com/DocProject/Project/License.aspx *
 ***********************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using mshtml;
using System.Windows.Forms;

namespace DaveSexton.Controls
{
	/// <summary>
	/// Provides event arguments for drag & drop events in the <see cref="HtmlEditor"/> controls.
	/// </summary>
	[Serializable]
	public class HtmlEditorDragDropEventArgs : HtmlEditorEventArgs
	{
		#region Public Properties
		public string DropValue
		{
			get
			{
				return Event.DataTransfer["Text"] as string;
			}
		}

		public HtmlElement Replacement
		{
			get
			{
				return replacement;
			}
			set
			{
				replacement = value;
			}
		}

		public string ReplacementHtml
		{
			get
			{
				if (replacement != null)
					return replacement.InnerHtml;
				else
					return replacementHtml;
			}
			set
			{
				replacementHtml = value;

				if (replacement != null)
					replacement.InnerHtml = replacementHtml;
			}
		}

		public HtmlDocument Document
		{
			get
			{
				return document;
			}
		}
		#endregion

		#region Private / Protected
		[NonSerialized]
		private readonly HtmlDocument document;
		[NonSerialized]
		private HtmlElement replacement;
		private string replacementHtml;
		#endregion

		#region Constructors
		/// <summary>
		/// Constructs a new instance of the <see cref="HtmlEditorDragDropEventArgs" /> class.
		/// </summary>
		public HtmlEditorDragDropEventArgs(HtmlDocument document, HtmlEvent @event)
			: base(@event)
		{
			if (document == null)
				throw new ArgumentNullException("document");

			this.document = document;
		}
		#endregion

		#region Methods
		[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1061:DoNotHideBaseClassMethods")]
		public new static HtmlEditorDragDropEventArgs FromEvent(HtmlDocument document, object htmlEvent)
		{
			return new HtmlEditorDragDropEventArgs(document, new HtmlEvent(document, (IHTMLEventObj) htmlEvent));
		}

		[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1061:DoNotHideBaseClassMethods")]
		public new static HtmlEditorDragDropEventArgs FromEvent(HtmlDocument document, object htmlEvent, HtmlElementEventArgs baseArgs)
		{
			return new HtmlEditorDragDropEventArgs(document, new HtmlEvent(document, (IHTMLEventObj) htmlEvent, baseArgs));
		}
		#endregion
	}
}
